//
//  ZTHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/22.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
// UI http://www.biaonimeia.com/file/483040/free

//h: (40+1+60) + 5 + (40*3+2) + 5 +40 = 273

#import "ZTHeaderView.h"
#define k15 15.0
#define k40 40
#define k5 5

@interface ZTHeaderView()
/**div0*/
@property (nonatomic, strong) UIView *div0;
/**自提门店 div01*/
@property (nonatomic, strong) UIView *div01;
/**010.自提门店*/
@property (nonatomic, strong) UILabel *zitiMenDianLb;



/**地址div02 添加手势 */
@property (nonatomic, strong) UIView *div02;
/**020.iconIv*/
@property (nonatomic, strong) UIImageView *iconIv;
/**023.右箭头*/
@property (nonatomic, strong) UIImageView *rightArrow;

//联系人信息 姓名 联系方式模块
/**div2*/
@property (nonatomic, strong) UIView *div2;
/**div20*/
@property (nonatomic, strong) UIView *div20;
/**200联系人信息*/
@property (nonatomic, strong) UILabel *lianxiRenMessageLb;


/**div21*/
@property (nonatomic, strong) UIView *div21;
/**210 姓名Lb*/
@property (nonatomic, strong) UILabel *nameLb;

/**div22*/
@property (nonatomic, strong) UIView *div22;
/**220 联系方式*/
@property (nonatomic, strong) UILabel *lianxiFangshiLb;



//============2019-1-12======
/**div3*/
@property (nonatomic, strong) UIView *div3;
/**餐品信息lb*/
@property (nonatomic, strong) UILabel *canpinMsgLb;
/**线*/
@property (nonatomic, strong) UIView *lightGrayLineView;
@end


@implementation ZTHeaderView

#pragma mark - 一 init

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    
    //div0
    [self addSubview:self.div0];
    [self.div0 addSubview:self.div01]; //自提门店
    [self.div01 addSubview:self.zitiMenDianLb];
    
    [self addSubview:self.div02]; //地址
    [self.div02 addSubview:self.iconIv];
    [self.div02 addSubview:self.shopNameLb];
    [self.div02 addSubview:self.addressLb];
    [self.div02 addSubview:self.rightArrow]; // >
    
    ///////////////////////////////////////
    
    
    
    //div2 : 9 个
    [self addSubview:self.div2];
    [self.div2 addSubview:self.div20]; //联系人x信息
    [self.div20 addSubview:self.lianxiRenMessageLb];//
    
    [self.div2 addSubview:self.div21]; //姓名
    [self.div21 addSubview:self.nameLb];
    [self.div21 addSubview:self.nameTf];
    
    
    [self.div2 addSubview:self.div22]; //联系方式
    [self.div22 addSubview:self.lianxiFangshiLb];
    [self.div22 addSubview:self.phoneTF];
    
    
    //餐品信息 2019-1-12
    [self addSubview:self.div3];
    [self.div3 addSubview:self.canpinMsgLb];
    [self.div3 addSubview:self.lightGrayLineView];
}


#pragma mark - 二 getter
//!!!!: ✅ ✅ div0 自提门店相关 ✅ ✅
- (UIView *)div0 { //灰色
    if (!_div0) {
        _div0 = [UIView new];
    }
    return _div0;
}

//!!!!:----div01 自提门店相关
- (UIView *)div01 {
    if (!_div01) {
        _div01 = [UIView new];
        _div01.backgroundColor = [UIColor whiteColor];
    }
    return _div01;
}
- (UILabel *)zitiMenDianLb {
    if (!_zitiMenDianLb) {
        _zitiMenDianLb = [UILabel new];
        //国际化
        _zitiMenDianLb.text = NSLocalizedString(CollectionShop, @"自提门店");
    }
    return _zitiMenDianLb;
}

//!!!!:----div02 地址相关
- (UIView *)div02 {
    if (!_div02) {
        _div02 = [UIView new];
        _div02.backgroundColor = [UIColor whiteColor];
        //添加手势
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickSelectAddressGes:)];
        [_div02 addGestureRecognizer:tapGes];
    }
    return _div02;
}
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"address"]];
    }
    return _iconIv;
}
- (UILabel *)shopNameLb {
    if (!_shopNameLb) {
        _shopNameLb = [UILabel new];
        
        //国际化
        _shopNameLb.text = [NSString rb_ChineseLanguage] ? @"店铺名字" : @"ShopName";
    }
    return _shopNameLb;
}
- (UILabel *)addressLb {
    if (!_addressLb) {
        _addressLb = [UILabel new];
        //国际化
        _addressLb.text = [NSString rb_ChineseLanguage] ? @"详细地址" : @"Address";
    }
    return _addressLb;
}
- (UIImageView *)rightArrow {
    if (!_rightArrow) {
        _rightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右箭头"]];
//        _rightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"address"]];
    }
    return _rightArrow;
}

//!!!!: ✅ ✅ div2 联系人信息相关 ✅ ✅
- (UIView *)div2 {
    if (!_div2) {
        _div2 = [UIView new];
        _div2.backgroundColor = kMainLightGrayColor;
    }
    return _div2;
}

//!!!!:====div20 联系人信息
- (UIView *)div20 {
    if (!_div20) {
        _div20 = [UIView new];
        _div20.backgroundColor = [UIColor whiteColor];
    }
    return _div20;
}
- (UILabel *)lianxiRenMessageLb {
    if (!_lianxiRenMessageLb) {
        _lianxiRenMessageLb = [UILabel new];
        //国际化
        NSString *lxrmsg = NSLocalizedString(ContactMessage, @"联系人信息");
        _lianxiRenMessageLb.text = lxrmsg;
    }
    return _lianxiRenMessageLb;
}

//!!!!:====div21 姓名
- (UIView *)div21 {
    if (!_div21) {
        _div21 = [UIView new];
        _div21.backgroundColor = [UIColor whiteColor];
    }
    return _div21;
}
- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        //国际化
        NSString *name = NSLocalizedString(Name, @"姓名");
        _nameLb.text = name;
    }
    return _nameLb;
}
- (UITextField *)nameTf {
    if (!_nameTf) {
        _nameTf = [[UITextField alloc] init];
        //国际化
        NSString *inputyouNameStr = NSLocalizedString(Tips_PutYouName, @"请输入姓名");
        _nameTf.placeholder = inputyouNameStr ;
        _nameTf.textAlignment = NSTextAlignmentRight;
    }
    return _nameTf;
}

//!!!!:====div22 联系方式
- (UIView *)div22 {
    if (!_div22) {
        _div22 = [UIView new];
        _div22.backgroundColor = [UIColor whiteColor];
    }
    return _div22;
}
- (UILabel *)lianxiFangshiLb {
    if (!_lianxiFangshiLb) {
        _lianxiFangshiLb = [UILabel new];
        //国际化
//        NSString *phone = @"联系方式";
        _lianxiFangshiLb.text = NSLocalizedString(LianXiFangShi, @"联系方式");
    }
    return _lianxiFangshiLb;
}

- (UITextField *)phoneTF {
    if (!_phoneTF) {
        _phoneTF = [[UITextField alloc] init];
        _phoneTF.textAlignment = NSTextAlignmentRight;
        //国际化
        NSString *xlfsStr = NSLocalizedString(Order_ContactPhone, @"请输入联系方式");
            _phoneTF.placeholder = xlfsStr;
        _phoneTF.keyboardType = UIKeyboardTypePhonePad; //2019-2-26电话键盘☎️
    }
    return _phoneTF;
}


//============2019-1-12======
- (UIView *)div3 {
    if (!_div3) {
        _div3 = [UIView new];
        _div3.backgroundColor = [UIColor whiteColor];
    }
    return _div3;
}
- (UILabel *)canpinMsgLb {
    if (!_canpinMsgLb) {
        _canpinMsgLb = [UILabel new];
        _canpinMsgLb.text = NSLocalizedString(Home_CanPinMsg, @"餐品信息");
    }
    return _canpinMsgLb;
}
- (UIView *)lightGrayLineView {
    if (!_lightGrayLineView) {
        _lightGrayLineView = [UIView new];
        _lightGrayLineView.backgroundColor = kMainLightGrayColor;
    }
    return _lightGrayLineView;
}

#pragma mark - 三 layout
//142 + 5 + 122 = 279
- (void)layoutSubviews {
    [super layoutSubviews];
    
    //40 + 60 + =102
    [self.div0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(102);
    }];

    //40+1+40+1+40
    [self.div2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.div0.mas_bottom).offset(k5);
        make.height.equalTo(@122);
    }];
    
    [self layoutDiv0];
    
    [self layoutDiv2];
    
    [self layoutDiv3];
}

//!!!!: ✅ ✅ div0 自提门店相关 ✅ ✅
- (void)layoutDiv0 {
    [self.div01 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.div0);
        make.height.equalTo(@40);
    }];
    [self.zitiMenDianLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div01.mas_left).offset(k15);
        make.centerY.equalTo(self.div01.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(100, 30));
        make.height.mas_equalTo(30);
        make.width.mas_greaterThanOrEqualTo(100); //2019-2-23国际化自适应宽度
    }];
    
    //地址
    [self.div02 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.div0);
        make.top.equalTo(self.div01.mas_bottom).offset(1); //1px线
        make.height.equalTo(@(60)); //h : 60
    }];
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div02.mas_left).offset(k15);
        make.size.mas_equalTo(CGSizeMake(15, 20));
        make.centerY.equalTo(self.div02.mas_centerY);
    }];
    [self.shopNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(5);
        make.right.equalTo(self.div02.mas_right).offset(-k15);
        make.top.equalTo(self.div02);
        make.height.equalTo(@(30));
    }];
    [self.addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shopNameLb.mas_bottom);
        make.left.equalTo(self.shopNameLb.mas_left);
        make.height.equalTo(@30);
        make.right.equalTo(self.rightArrow.mas_left);//.offset(-k15);
    }];
    [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.right.equalTo(self.div02.mas_right).offset(-k15);
        make.centerY.equalTo(self.div02.mas_centerY);
    }];
}

//!!!!: ✅ ✅ div2 联系人信息相关 ✅ ✅
- (void)layoutDiv2 {
    //40
    [self.div20 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.div2);
        make.height.mas_equalTo(40);
    }];
    [self.lianxiRenMessageLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div20.mas_left).offset(k15);
        make.centerY.equalTo(self.div20.mas_centerY);
        make.height.mas_equalTo(30);
        make.width.mas_greaterThanOrEqualTo(100); //国际化自适应宽度
    }];
    
    
    
    //40
    [self.div21 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.div2);
        make.top.equalTo(self.div20.mas_bottom).offset(1);
        make.height.mas_equalTo(40);
    }];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div21.mas_left).offset(k15);
        make.size.mas_equalTo(CGSizeMake(80, 22));
        make.centerY.equalTo(self.div21.mas_centerY);
    }];
    [self.nameTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLb.mas_right);
        make.right.equalTo(self.div21.mas_right).offset(-k15);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.div21.mas_centerY);
    }];
    

    [self.div22 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left);
        make.right.equalTo(self.div2.mas_right);
        make.top.equalTo(self.div21.mas_bottom).offset(1);
        make.height.mas_equalTo(40);
    }];
    [self.lianxiFangshiLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div22.mas_left).offset(k15);
        make.centerY.equalTo(self.div22.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(120, 30));
        make.height.mas_equalTo(30);
        make.width.mas_greaterThanOrEqualTo(100); //国家化宽度自适应
    }];
    
    [self.phoneTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.div22.mas_right).offset(-k15);
        make.left.equalTo(self.lianxiFangshiLb.mas_right);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self.div22.mas_centerY);
    }];
}

//!!!!:2019-1-12 div3
- (void)layoutDiv3 {
    [self.div3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.div2.mas_bottom).offset(k5);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(k40);
    }];
    [self.canpinMsgLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div3.mas_left).offset(k15);
        make.right.equalTo(self.div3.mas_right).offset(-k5);
        make.top.equalTo(self.div3.mas_top);
        make.bottom.equalTo(self.div3.mas_bottom).offset(2);
    }];
    [self.lightGrayLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div3.mas_left).offset(k15);
        make.right.equalTo(self.div3.mas_right).offset(-k15);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.div3.mas_bottom);
    }];
}



#pragma mark - 点击时间
- (void)clickSelectAddressGes:(UITapGestureRecognizer *)tap {

    if (self.ztheaderViewBlock) {
        self.ztheaderViewBlock();
    }
}

@end
